package com.wgj.android.adapter;

import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.widget.ImageView;

import com.jiaai.xui.adapter.XRecyclerViewAdapter;
import com.jiaai.xui.adapter.XViewHolder;
import com.jiaai.xui.utils.XDateUtils;
import com.jiaai.xui.utils.imageload.ImageLoader;
import com.jiaai.xui.utils.imageload.XImage;
import com.wgj.android.R;
import com.wgj.android.entity.TVComment;
import com.wgj.android.utils.DateUtils;

import java.util.List;

/**
 * Created by Administrator on 2018/3/16.
 */

public class TVCommentAdapter extends XRecyclerViewAdapter<TVComment> {
    public TVCommentAdapter(@NonNull RecyclerView mRecyclerView, List<TVComment> dataLists) {
        super(mRecyclerView, dataLists, R.layout.reply_item);
    }


    @Override
    protected void bindData(XViewHolder holder, TVComment tvComment, int i) {

        XImage.getInstance().load((ImageView) holder.getView(R.id.headIv),tvComment.getAvater());

        holder.setText(R.id.tv_name,tvComment.getM_nick());
        if(!TextUtils.isEmpty(tvComment.getFeedName())){
            SpannableStringBuilder spannable = new SpannableStringBuilder("回复 "+tvComment.getFeedName()+" :"+tvComment.getMessage());
            spannable.setSpan(new ForegroundColorSpan(Color.RED),2,tvComment.getFeedName().length()+2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            holder.setText(R.id.tv_reply, spannable.toString());
        }else {
            holder.setText(R.id.tv_reply,tvComment.getMessage());
        }

        holder.setText(R.id.tv_time, XDateUtils.millis2String(tvComment.getTime(),"yyyy年MM月dd"));

    }
}
